home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / POKER.TST / POKERTST.C < prev    next >
C/C++ Source or Header  |  1996-03-30  |  5KB  |  157 lines

  1. /* ============ */
  2. /* PokerTst.c    */
  3. /* ============ */
  4. #include <defcodes.h>
  5. #include <miscdefs.h>
  6. #include <pokrdefs.h>
  7. #include <mconf.h>
  8. #include <math.h>
  9.  
  10. #define    NUM_PROBS    100
  11. #define LOW_PROB    1.0e-4
  12.  
  13. /* ==================================================================== */
  14. /* PokerTest - Runs Poker Test on random data roughly according to Knuth */
  15. /* ==================================================================== */
  16. void
  17. main(void)
  18. {
  19.     int        k;
  20.     double  ChiSqProb[NUM_PROBS];
  21.     double  DegFree, LoLimit, HiLimit;
  22.  
  23.     double  KnMinusProb, KnMinusStat, KnPlusProb, KnPlusStat;
  24.  
  25.     INIT_DATA_STRU  InitialData;
  26.     POKER_DATA_STRU PokerData;
  27.  
  28.     AbortGracefully();            /* Make ^C act reasonably */
  29.  
  30.     printf("\tP O K E R  T E S T\n\n");
  31.     GetInitialData(&InitialData);
  32.     fflush(NULL); fprintf(stderr, "\n");
  33.  
  34.     /* -------------------------- */
  35.     /* Print Initial Data Entries */
  36.     /* -------------------------- */
  37.     printf("Starting Seed = %u%s\n", InitialData.UserSeed,
  38.     (InitialData.SeedSrce == (UINT)(-1)) ?
  39.         " (Unsigned Integer Part of Time of Day)" : "");
  40.  
  41.     printf("Generator     = %s\n", InitialData.GenName);
  42.  
  43.     PokerData.RandFun = InitialData.RandFun;
  44.  
  45.     SetPokerControls(&PokerData);
  46.  
  47.     /* ---------------------------- */
  48.     /* Initialize Count of Variates */
  49.     /* ---------------------------- */
  50.     PokerData.TotNumGen = 0;
  51.  
  52.     if (!PokerData.CallStatusOK)
  53.     {
  54.     int    HandCountOK;
  55.     HandCountOK =
  56.         (PokerData.CardsPerHand - PokerData.NotEnough) >= MIN_CARDS;
  57.     printf("\nOf the %d Possible Categories, ",
  58.         PokerData.CardsPerHand);
  59.  
  60.     if (PokerData.NotEnough == 1)
  61.     {
  62.         printf("1 Has a Cell Expectation");
  63.     }
  64.     else
  65.     {
  66.         printf("%d Have Cell Expectations", PokerData.NotEnough);
  67.     }
  68.     printf(" Less Than\nthe Number Requested (%d)",
  69.         PokerData.UserCellExpect);
  70.     if (HandCountOK)
  71.     {
  72.         printf(" and Will be Lumped With Others.\n");
  73.     }
  74.     else
  75.     {
  76.         printf(".\n");
  77.     }
  78.     printf("For the Inputs That You Have Provided At Least %lu"
  79.         " Hands are Required\nto Fill All Categories.\n",
  80.         PokerData.UserNumHands);
  81.     if (PokerData.UserCellExpect != MIN_CELL_XPCT)
  82.     {
  83.         printf("For a Minimum of %d Samples Per Category At"
  84.         " Least %lu Hands are Required.\n", MIN_CELL_XPCT,
  85.         PokerData.IdealNumHands);
  86.     }
  87.     if (!HandCountOK)
  88.     {
  89.         printf("At Least %d Cards Per Hand Are Required.\n",
  90.         MIN_CARDS);
  91.         printf("Your Inputs Allow Only %d.\n",
  92.         PokerData.CardsPerHand - PokerData.NotEnough);
  93.         exit(1);
  94.     }
  95.     }
  96.     fflush(NULL);
  97.     DegFree = PokerData.CardsPerHand - PokerData.NotEnough - 1;
  98.     ChiSqDist(LOW_PROB, DegFree, &LoLimit, &HiLimit);
  99.  
  100.     P(printf("DegFree = %f, LoLimit = %.10e, HiLimit = %.10e\n",
  101.     DegFree, LoLimit, HiLimit));
  102.     /* ------------------------- */
  103.     /* Generate Random Numbers,  */
  104.     /* Calculate Chi-Square Data */
  105.     /* ------------------------- */
  106.     for (k = 0; k < NUM_PROBS; ++k)
  107.     {
  108.     CalcPokerChiSq(&PokerData);
  109.  
  110.     fprintf(stderr, "\rPass %3d (of %d), %8ld  Total Random Numbers",
  111.         k+1, NUM_PROBS, PokerData.TotNumGen);
  112.  
  113.     if (PokerData.PokerChiSq <= LoLimit)
  114.     {
  115.         ChiSqProb[k] = LOW_PROB;
  116.     }
  117.     else if (PokerData.PokerChiSq >= HiLimit)
  118.     {
  119.         ChiSqProb[k] = 1.0 - LOW_PROB;
  120.     }
  121.     else
  122.     {
  123.         ChiSqProb[k] = chdtr(DegFree, PokerData.PokerChiSq);
  124.     }
  125.     if (ChiSqProb[k] < 0)
  126.     {
  127.         fprintf(stderr, "\nChiSqFreq(): Function chdtr() "
  128.         "Returned Negative Probability -  Can't Happen.\n");
  129.     }
  130.     P(printf("Pass %3d Poker Chi-Square Statistic = %f\n", k+1,
  131.        PokerData.PokerChiSq));
  132.     P(printf("\t Chi-Square Probability on %.f"
  133.         " Degrees of Freedom = %.4f\n", DegFree, ChiSqProb[k]));
  134.  
  135.     }
  136.  
  137.     /* -------------------------------------------------------- */
  138.     /* Calculate K-S on Chi-Square Statistics and Probabilities */
  139.     /* -------------------------------------------------------- */
  140.     fflush(NULL);fprintf(stderr, "\n");
  141.     KSCalc(ChiSqProb, NUM_PROBS,
  142.         &KnPlusStat, &KnPlusProb,
  143.          &KnMinusStat, &KnMinusProb);
  144.  
  145.    printf("\nKolmogorov-Smirnov Statistics and Probabilities"
  146.     " on Chi-Square Data\n");
  147.  
  148.    printf("\tK(%d)+ = %f (Knuth) or %9f%%\n", NUM_PROBS,
  149.     sqrt((double)NUM_PROBS)*KnPlusStat, 100*KnPlusProb);
  150.  
  151.    printf("\tK(%d)- = %f (Knuth) or %9f%%\n", NUM_PROBS,
  152.     sqrt((double)NUM_PROBS)*KnMinusStat, 100*KnMinusProb);
  153.  
  154.     printf("\nThis Run Required %ld Random Numbers (%s)\n\n",
  155.     PokerData.TotNumGen, InitialData.GenName);
  156. }
  157.